/* 
 * File:   main.c
 * Author: Hugo !
 *
 * Created on 20 mars 2012, 13:56
 */

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>

char * commands[3] = {
    "ls -l",
    "sort -k 5",
    "sort -k 2 -n"
           
};

/*
 * 
 */
int main(int argc, char** argv) {
    int cursor = 1;
    __pid_t pid = fork();
    
    int anonPipe1[2];
    pipe(anonPipe1);
            
    if(pid == -1) {
        perror("fork");
        exit(-1);
    }else if(pid == 0) {
        close(anonPipe1[0]);
        close(1);
        dup(anonPipe1[1]);
        close(anonPipe1[1]);
        printf("J'execute\n");
        //char * argv[] = { "ls", "-l", NULL};
        execvp(argv[0], argv);
        printf("Fini");
        
    }
    else{
        close(anonPipe1[1]);
        //close(0);
        wait();
        char c;
        read(anonPipe1[0], &c, 1);
        printf("Child Said : %s\n", c);
    }
    
    return (EXIT_SUCCESS);
}

